import React from 'react';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import { createForm } from 'rc-form';
import { NavBar, List, InputItem } from 'antd-mobile';

function AddNewDept({
    dispatch, form,
}) {
  const { getFieldProps, getFieldValue } = form;
  function rightClick() {
    if (getFieldValue('customDept') === undefined) {
      dispatch({
        type: 'physicianAuth/selectDeptSuccess',
        payload: '',
      });
      dispatch(routerRedux.push('/physicianAuth'));
    }
    dispatch({
      type: 'physicianAuth/selectDeptSuccess',
      payload: {
        name: getFieldValue('customDept'),
      },
    });
    dispatch(routerRedux.push('/physicianAuth'));
  }
  return (
    <div>
      <NavBar
        leftContent="取消"
        onLeftClick={() => {
          dispatch(routerRedux.push('/selectDept'));
        }}
        rightContent={
          <div onClick={rightClick} style={{ marginRight: '25px' }}>完成</div>
        }
        mode="light"
      ><span style={{ color: '#33333' }}>添加科室</span></NavBar>
      <List renderHeader={() => '请输入您的科室名称  （2-12字）'}>
        <InputItem
          {...getFieldProps('customDept')}
          placeholder="请输入您的科室名称  （2-12字）"

        />
      </List>
    </div>
  );
}

function mapStateToProps({ physicianAuth }) {
  return { physicianAuth };
}

export default connect(mapStateToProps)(createForm()(AddNewDept));
